package com.ssm.user.designPattern.builderPattern;


public class Boy {

    private String name;

    private String nickName;

    private Integer age;

    private Integer hight;

    // 构造方法私有化，不然客户端就会直接调用构造方法了
    private Boy(String name, String nickName, Integer age, Integer hight) {
        this.age = age;
        this.name = name;
        this.hight = hight;
        this.nickName = nickName;
    }

    @Override
    public String toString() {
        return "Boy{" +
                "name='" + name + '\'' +
                ", nickName='" + nickName + '\'' +
                ", age=" + age +
                ", hight=" + hight +
                '}';
    }

    // 静态方法，用于生成一个 Builder，这个不一定要有，不过写这个方法是一个很好的习惯，
    // 有些代码要求别人写 new User.UserBuilder().a()...build() 看上去就没那么好
    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {
        // 下面是和 Boy 一模一样的一堆属性
        private String name;

        private String nickName;

        private Integer age;

        private Integer hight;

        private Builder() {
        }

        // 链式调用设置各个属性值，返回 this，即 UserBuilder(调用build()方法后，才返回Boy对象)
        public Builder name(String name) {
            this.name = name;
            return this;
        }

        public Builder nickName(String nickName) {
            this.nickName = nickName;
            return this;
        }

        public Builder age(Integer age) {
            this.age = age;
            return this;
        }

        public Builder hight(Integer hight) {
            this.hight = hight;
            return this;
        }

        public Boy build() {
            return new Boy(name, nickName, age, hight);
        }
    }
}